#!/bin/python3
'''
File: FILENAME: sstd.py
Author: lmsdscav
Description: 
 * Made by lmsdscav
 * SSTD method for GNU/Linux&Windows&Darwin
 * Copyright
 * Wechat ID: HerobrinHIM
'''
if __name__=="__main__":
	print("==>请不要直接运行sstd.py。")
	exit()
import os
class _Getch:
    def __init__(self):
        try:
            self.impl = _GetchWindows()
        except ImportError:
            self.impl = _GetchUnix()
    def __call__(self): return self.impl()
class _GetchUnix:
    def __init__(self):
        import tty, sys
    def __call__(self):
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch
class _GetchWindows:
    def __init__(self):
        import msvcrt
    def __call__(self):
        import msvcrt
        return msvcrt.getch()
Getch = _Getch()
f=""
prompt='>'
c27=""
width = os.get_terminal_size().columns
def set_p(p='>'):
    global prompt
    prompt=p
def set_c27(p='exit()'):
    global c27
    c27=p
def input(sprompt=prompt):
    global f,prompt
    while True:
        print("\r"+sprompt+f,end='')
        getch=Getch()
        print("\r"+" "*(width-1)+'\r'+sprompt,end='')
        if len(f)>width-2-len(sprompt):
            pass
        elif getch=='\r':
            pass
        elif getch==chr(27):
            #put("ESC PRESSED codec27")
            exec(c27)
        elif getch==chr(181):
            put("|µ•SSTD: Force EXIT•µ|")
            exit()
        elif getch==chr(127):
            pass
        else:
            f+=getch
        if getch=='\r':
            print("\r",end='')
            #print(f)
            #f=''
            k=f
            f=''
            return k
            #print(f)
            break
        elif getch==chr(127):
            f=f[:-1]
        print("\r"+" "*(width-1)+"\r",end='')
import time
def put(a,end='\n'):
    global prompt
    print("\r"+" "*(width-1),end='\r')
    print("\r"+a,end=end)
    print('\r'+prompt+f,end='')
def check():
    ck=input()
    for x in ck:
        put(str(ord(x)))
def clear():
    print("\r"+" "*(width-1),end='\r')